Quiz I:
Date: Tuesday, Feb. 10
Material: Chapter 1 and Chapter 2
Where: During class hours
Format: MCQ + TF (Quiz) + Coding problem (classwork)

---> Agenda:

1) Increment/decrement operators

++ ---> used to increment a variable by 1
unary operator

x++ ---> postfix version of ++
++x ---> prefix version of ++

int x = 5;

x++; // x = 6

y = ++x; // x = 7, y = 7
prefix ++ has a higher precedence relative to assignment operator = 
Rewritten to: ++x; y = x;

z = y++; // z = 7, y = 8
postfix ++ has lower precedence compared to =
Rewritten to: z = y; y++;

Example#1: IncrementDemo.java

There are 3 different ways to increment val by 1:
1.a) val = val + 1;
1.b) val++; or ++val;
1.c) val += 1;

val = val * 2; <=> val *= 2;
val = val / 3; <=> val /= 3;
val = val % 4; <=> val %= 4;


2) Data conversion

2.a) Assignment

int money = 25;
double dollars = money;

System.out.println(money); // 25
System.out.println(dollars); // 25.0

double dollars = 25.6;
int money = dollars; // Compile-time error

Assignment operator (=) does not support narrowing conversions

2.b) Promotion

7.0 / 2 ---> 7.0 / 2.0 ---> 3.5

"Hi" + 5 ---> "Hi" + "5" ---> "Hi5"

2.c) Cast operator

double dollars = 25.6;
int money = (int) dollars; // 25

1	4	6

int sum = 11;
int count = 3;

double avg =  sum / (double) count;

System.out.println("Avg: " + avg); // 3.0

(double) sum / count;

If division happens first, answer = 3.0 
If casting happens first, 11.0 / 3 ---> 11.0 / 3.0 ---> 3.333.... (Cast operator does have
higher priority than division operator).

(double) (sum / count) yields 3.0 !


3) Interactive program using Scanner class

8 primitive data types: 
byte, short, int, long, float, double, char, boolean

Scanner is a class data type (DIU)

Aim: get a line of text from the user and then echo it back to the screen

import java.lang.*;

Example#2: Echo.java

a vs a()

String nextLine() // signature or header of the method



